import request from '../../utils/request'
import { requestString } from '../../utils/request'
//---------------------------------订单

/**
 * 创建订单
 * @param order
 * @returns {Promise.<Object>}
 */
export async function createOrder({ order }) {
    return requestString(apiPath.zbtie + "/api/order", {
        method: 'POST',
        data: { ...order }
    });
}

/**
 * 分页查询订单
 *
 * @param customerNo
 * @param customerName
 * @param orderNo
 * @param contractNo
 * @param declarationType
 * @param status
 * @param page
 * @returns {Promise.<Object>}
 */
export async function queryOrders({ applyFlag, buyerId, buyerName, orderNo, contractNo, declarationType, status, page, createBegin, createEnd, supplierId }) {
    return request(apiPath.zbtie + "/api/order", {
        method: 'GET',
        data: { applyFlag, buyerId, buyerName, orderNo, contractNo, declarationType, status, createBegin, createEnd, supplierId, page: page.page, size: page.size }
    });
}

/**
 * 查询订单信息列表
 *
 * @param orderNo
 * @param contractNo
 * @return
 */
export async function queryOrderByNo({ orderNo, contractNo }){
    return request(apiPath.zbtie+ "/api/order/query", {
        method: 'GET',
        data: { orderNo, contractNo }
    });
}

/**
 * 删除订单
 * @param id
 * @returns {Promise.<Object>}
 */
export async function deleteOrderById({ id }) {
    return request(apiPath.zbtie + "/api/order/" + id, {
        method: 'DELETE'
    });
}

/**
 * 复制订单
 * @param id
 * @returns {Promise.<Object>}
 */
export async function copyOrderById({ id }) {
    return request(apiPath.zbtie + "/api/order/" + id + "/copy", {
        method: 'PUT'
    });
}


/**
 * 根据id获取订单详情
 * @param id
 * @returns {Promise.<Object>}
 */
export async function getOrderById({ id }) {
    return request(apiPath.zbtie + "/api/order/" + id, {
        method: 'get'
    });
}


/**
 * 复制产品
 * @param id
 * @returns {Promise.<Object>}
 */
export async function copyProductById({ id }) {
    return request(apiPath.zbtie + "/api/product/" + id + "/copyproduct", {
        method: 'PUT'
    });
}

/**
 * 查询开票人
 *
 * @param cstId
 * @param status
 * @returns {Promise.<Object>}
 */
export async function queryDrawers({ cstId, status }) {
    return request(apiPath.zbtie + "/api/drawers/all", {
        method: 'GET',
        data: { cstId, status }
    });
}

/**
 * 查询联系人
 *
 * @param cstId
 * @param status
 * @returns {Promise.<Object>}
 */
export async function queryLinkmans({ cstId, status }) {
    return request(apiPath.zbtie + "/api/" + cstId + "/linkmans", {
        method: 'GET',
        data: { status }
    });
}


/**
 * 新增联系人
 * @param linkman
 * @returns {Promise.<Object>}
 */
export async function createLinkman({ linkman }) {
    return request(apiPath.zbtie + "/api/linkman", {
        method: 'POST',
        data: linkman
    });
}


/**
 * 查询货物存放地址
 *
 * @param cstId
 * @param status
 * @returns {Promise.<Object>}
 */
export async function queryAddresses({ cstId, status }) {
    return request(apiPath.zbtie + "/api/" + cstId + "/goodsaddress", {
        method: 'GET',
        data: { status }
    });
}

/**
 * 查询境外买家
 *
 * @param cstId
 * @param status
 * @returns {Promise.<Object>}
 */
export async function queryBuyers({ cstId, status }) {
    return request(apiPath.zbtie + "/api/buyers/all", {
        method: 'GET',
        data: { cstId, status }
    });
}


/**
 * 新增货物存放地址
 * @param address
 * @returns {Promise.<Object>}
 */
export async function createAddress({ address }) {
    return request(apiPath.zbtie + "/api/goodsaddress", {
        method: 'POST',
        data: address
    });
}

/**
 * 修改订单
 * @param order
 * @returns {Promise.<Object>}
 */
export async function updateOrder({ order }) {
    return requestString(apiPath.zbtie + "/api/order", {
        method: 'PUT',
        data: { ...order }
    });
}

/**
 * 终止订单/取消订单
 * @param id
 * @returns {Promise.<Object>}
 */
export async function cancelOrderById({ id }) {
    return request(apiPath.zbtie + "/api/order/" + id + "/cancelorder", {
        method: 'PUT'
    });
}

/**
 * 确认收函
 * @param id
 * @returns {Promise.<Object>}
 */
export async function confirmLetterById({ id, outputService }) {
    return request(apiPath.zbtie + "/api/order/" + id + "/confirmletter", {
        method: 'PUT',
        data: { outputService }
    });
}

/**
 * 根据客户查询订单境内货源地
 *
 * @param cstId
 * @returns {Promise.<Object>}
 */
export async function querySupplyGoods({ cstId }) {
    return request(apiPath.zbtie + "/api/drawer/supplygoods", {
        method: 'GET',
        data: {cstId, status: '4'}
    });
}



//------------------------------订单费用

/**
 * 分页查询费用列表
 *
 * @param id
 * @param status
 * @param costPage
 * @returns {Promise.<Object>}
 */
export async function queryOrderCost({ orderId, type, status, provierName, costPage }) {
    return request(apiPath.zbtie + "/api/orderCharge", {
        method: 'GET',
        data: {orderId, type, status, provierName, page: costPage.page, size: costPage.size }
    });
}


/**
 * 添加费用
 *
 * @param id
 * @returns {Promise.<Object>}
 */
export async function addOrderCost(data) {
    return request(apiPath.zbtie + "/api/orderCharge", {
        method: 'POST',
        data
    });
}


/**
 * 更新费用
 *
 * @param id
 * @returns {Promise.<Object>}
 */
export async function updateOrderCost(data) {
    return request(apiPath.zbtie + "/api/orderCharge", {
        method: 'PUT',
        data
    });
}


/**
 * 删除费用
 *
 * @param id
 * @returns {Promise.<Object>}
 */
export async function deleteOrderCost({ id }) {
    return request(apiPath.zbtie + "/api/orderCharge/" + id, {
        method: 'DELETE',
    });
}

/**
 * 申报/审批 费用
 *
 * @param id
 * @returns {Promise.<Object>}
 */
export async function applyOrderCost({ cost }) {
    return request(apiPath.zbtie + "/api/ordercharge/apply", {
        method: 'PUT',
        data: cost
    });
}

/**
 * 确认费用收齐
 *
 * @param id
 * @param status {1: 通关收齐, 2:跟单收齐}
 * @returns {Promise.<Object>}
 */
export async function confirmCost({ id, status }) {
    return request(apiPath.zbtie + "/api/order/" + id + "/collectedordercharge", {
        method: 'PUT',
        data: { status }
    });
}


/**
 * 查询通关专员
 *
 * @param cstId
 * @param status
 * @returns {Promise.<Object>}
 */
export async function queryTgManagers() {
    return request(apiPath.authcenter + "/api/user/tgmanager", {
        method: 'GET',
    });
}

export async function getOrderCurrency2USDRate({ currency }) {
    return request(apiPath.zbtie + "/api/orderUsdRate", {
        method: 'GET',
        data: { currency }
    });
}

/**
 * 取消确认费用收齐
 *
 */
export async function cancelChargeConfirm(data) {
    return request(apiPath.zbtie + "/api/order//cancelChargeConfirm", {
        method: 'PUT',
        data
    });
}